package com.xiaoxie.cloud.controller;

import cn.hutool.core.util.IdUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class PayCircuitController {

    // Resilience4j 测试
    /*@GetMapping("/pay/circuit/{id}")
    public String myCircuit(@PathVariable("id") Integer id){
        if (id < 0) throw new RuntimeException("circuit id 不能为负数！");
        if (id == 9999) {
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        return "Hello,circuit! inputId: " + id + "\t" + IdUtil.simpleUUID();
    }*/

    // Resilience4j bulkhead 测试
    @GetMapping("/pay/bulkhead/{id}")
    public String myBulkhead(@PathVariable("id") Integer id) {
        // System.out.println("进入...." + id);
        if (id < 0) throw new RuntimeException("bulkhead id 不能为负数！");
        if (id == 9999) {
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        return "Hello, bulkhead! inputId:" + id + "\t" + IdUtil.simpleUUID();
    }

    // Resilience4j ratelimit 测试
    @GetMapping("/pay/ratelimit/{id}")
    public String myRatelimit(@PathVariable("id") Integer id) {
        return "Hello, ratelimit! inputId:" + id + "\t" + IdUtil.simpleUUID();
    }

}
